package com.dxl.system.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dxl.base.Result;
import com.dxl.base.Results;
import com.dxl.base.util.LocalDateTimeUtil;
import com.dxl.base.util.UpDownFileUtil;
import com.dxl.system.mapper.*;
import com.dxl.system.model.*;
import com.dxl.system.service.GroupsService;
import com.dxl.system.service.LabelService;
import com.dxl.system.service.NoteService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <b> 文件服务接口实现类
 * </b><br><br><i>Description</i> :
 * <br>Date: 2019-09-25    <br>Author : dxl
 */
@Service
public class NoteServiceImpl extends ServiceImpl<NoteMapper,Note> implements NoteService {

    @Autowired(required = false)
    private NoteMapper noteMapper;
    @Autowired(required = false)
    private LabelNoteMapper labelNoteMapper;
    @Autowired(required = false)
    private GroupsMapper groupsMapper;
    @Autowired(required = false)
    private GroupsMapper groupsMapper222;
    @Autowired(required = false)
    private LabelService labelService;
    @Autowired(required = false)
    private ConfigMapper configMapper;
    @Autowired(required = false)
    private TypeMapper typeMapper;
    @Autowired(required = false)
    private GroupsService groupsService;

    /**
     * <b> 上传文件
     * </b><br><br><i>Description</i> : 不能为空：文件标题-note_title ；不能重复：文件标题-note_title
     * @return String
     * <br><br>Date: 2019-09-25    <br>Author : dxl
     */
    @Override
    public Result upOne(MultipartFile multipartfile, String noteNote, Integer groupId, Integer seriesId, String typeSuffix, Integer typeId) {
        if(groupId == null || "".equals(groupId)){
            return Results.failure("请选择分组:(");
        }
        File file = null;
        try {
            file = UpDownFileUtil.multipartFileToFile(multipartfile);
        } catch (Exception e) {
            return Results.failure("上传失败，MultipartFile转File错误:(");
        }
        //自动判断是否有该类型
        if(file == null){
            return Results.failure("不能上传空文件:(");
        }
        int indexDian = file.getName().lastIndexOf(".");
        typeSuffix = file.getName().substring(indexDian+1,file.getName().length());
        QueryWrapper<Type> typeQueryWrapper = new QueryWrapper<>();
        typeQueryWrapper.eq("type_suffix",typeSuffix);
        Type type = typeMapper.selectOne(typeQueryWrapper);
        if(type == null){
            return Results.failure("上传失败，请先创建该文件类型:(");
        }
        typeId = type.getId();

        QueryWrapper<Note> noteQueryWrapper = new QueryWrapper<>();
        noteQueryWrapper.eq("note_title",file.getName().substring(0,file.getName().length()-typeSuffix.length()-1)).eq("group_id",groupId).eq("type_suffix",typeSuffix);
        List<Note> noteList = noteMapper.selectList(noteQueryWrapper);
        if(noteList.size() > 0){
            return Results.failure("上传失败，文件名称重复:(");
        }
        QueryWrapper<Config> configQueryWrapper = new QueryWrapper<>();
        configQueryWrapper.eq("config_key","FileRootPath");
        Config config = configMapper.selectOne(configQueryWrapper);
        if(config == null || config.getConfigKey() == null){
            return Results.failure("系统中无根路径配置，请在数据库中先配置config_key为FileRootPath的记录:(");
        }
        if(config.getConfigValue().substring(config.getConfigValue().length()-1).equals("/")){
            config.setConfigValue(config.getConfigValue().substring(0,config.getConfigValue().length()-1));
        }
        Groups groups = groupsMapper.selectById(groupId);
        File file1 = new File(config.getConfigValue()+"/"+groups.getNote()+"file/"+file.getName());
        if(!(file1.getParentFile().exists())){  //判断d:\demo目录是否存在
            file1.getParentFile().mkdirs();
        }
        try {
            multipartfile.transferTo(file1);
        } catch (IOException e) {
            return Results.failure("上传失败:(");
        }

        Note note = new Note();
        note.setNoteTitle(file.getName().substring(0,file.getName().length()-typeSuffix.length()-1));
        note.setNote(noteNote);
        note.setGroupId(groupId);
        note.setSeriesId(seriesId);
        note.setTypeSuffix(typeSuffix);
        note.setTypeId(typeId);
        note.setCreateTime(LocalDateTimeUtil.getLocalDateTime());
        Result result = isNoteAddable(note);
        boolean flag = (boolean) result.getData();
        if(!flag){
            return Results.failure(result.getMsg());
        }
        noteMapper.insert(note);

        return Results.success("上传成功:)");
    }

    /**
     * <b> 插入文件
     * </b><br><br><i>Description</i> : 不能为空：文件标题-note_title ；不能重复：文件标题-note_title
     * @param note Note
     * @return com.dxl.base.Result Note
     * <br><br>Date: 2019-09-25    <br>Author : dxl
     */
    @Override
    public Result addOne(Note note) {
        note.setNoteTitle(note.getNoteTitle().trim());
        Result result = isNoteAddable(note);
        boolean flag = (boolean) result.getData();
        if(!flag){
            return Results.failure(result.getMsg());
        }
        note.setCreateTime(LocalDateTimeUtil.getLocalDateTime());

        Groups groups = groupsMapper.selectById(note.getGroupId());
        QueryWrapper<Config> configQueryWrapper = new QueryWrapper<>();
        configQueryWrapper.eq("config_key","FileRootPath");
        Config config = configMapper.selectOne(configQueryWrapper);
        if(config == null || config.getConfigKey() == null){
            return Results.failure("系统中无根路径配置，请在数据库中先配置config_key为FileRootPath的记录:(");
        }
        if(config.getConfigValue().substring(config.getConfigValue().length()-1).equals("/")){
            config.setConfigValue(config.getConfigValue().substring(0,config.getConfigValue().length()-1));
        }
        File file = new File(config.getConfigValue()+"/"+groups.getNote()+"file/"+note.getNoteTitle()+"."+note.getTypeSuffix());
        //在磁盘下创建一层目录,并且在目录下创建文件文件
        if(!(file.getParentFile().exists())){  //判断d:\demo目录是否存在
            file.getParentFile().mkdirs();
        }
        if(!file.exists()){
            try {
                file.createNewFile();
            } catch (IOException e) {
                //e.printStackTrace();
                return Results.failure("创建文件失败:(");
            }
        }
        noteMapper.insert(note);
        return Results.successWithData(note);
    }

    /**
     * <b> 分配标签给文件
     * </b><br><br><i>Description</i> :
     * @param noteId Integer，labelIds -List: Integer
     * @return com.dxl.base.Result Note
     * <br><br>Date: 2019-09-25    <br>Author : dxl
     */
    @Override
    @Transactional
    public Result addLabelToNote(Integer noteId, List<Integer> labelIds) {
        for(Integer labelId : labelIds){
            LabelNote labelNote = new LabelNote();
            labelNote.setNoteId(noteId);
            labelNote.setLabelId(labelId);
            QueryWrapper<LabelNote> labelNoteWrapper = new QueryWrapper<LabelNote>(labelNote);
            if(labelNoteMapper.selectList(labelNoteWrapper).size() == 0){
                labelNoteMapper.insert(labelNote);
            }
        }
        return Results.successWithData(true);
    }

    /**
     * <b> 删除文件
     * </b><br><br><i>Description</i> : 
     * @param noteIds List: Integer
     * @return com.dxl.base.Result int
     * <br><br>Date: 2019-09-25    <br>Author : dxl
     */
    @Override
    public Result delByIds(List<Integer> noteIds) {
        int num = noteMapper.deleteBatchIds(noteIds);
        return Results.successWithData(num);
    }

    /**
     * <b> 删除文件及文件（md 和 html）
     * </b><br><br><i>Description</i> :
     * @param noteIds
     * @return com.dxl.base.Result
     * <br><br>Date: 2019/10/1 19:35    <br>Author : dxl
     */
    @Override
    @Transactional
    public Result delAndFile(List<Integer> noteIds) {
        QueryWrapper<Config> configQueryWrapper = new QueryWrapper<>();
        configQueryWrapper.eq("config_key","FileRootPath");
        Config config = configMapper.selectOne(configQueryWrapper);
        if(config == null || config.getConfigKey() == null){
            return Results.failure("系统中无根路径配置，请在数据库中先配置config_key为FileRootPath的记录:(");
        }
        if(config.getConfigValue().substring(config.getConfigValue().length()-1).equals("/")){
            config.setConfigValue(config.getConfigValue().substring(0,config.getConfigValue().length()-1));
        }
        for(Integer noteId : noteIds){
            Note note = noteMapper.selectById(noteId);
            Groups groups = groupsMapper.selectById(note.getGroupId());
            File file = new File(config.getConfigValue()+"/"+groups.getNote()+"file/"+note.getNoteTitle()+"."+note.getTypeSuffix());
            if(file.exists()){
                file.delete();
            }
            File file2 = new File(config.getConfigValue()+"/"+groups.getNote()+"html/"+note.getNoteTitle()+".html");
            if(file2.exists()){
                file2.delete();
            }
            delAllLabelFromNote(noteId);
        }
        noteMapper.deleteBatchIds(noteIds);
        return Results.success();
    }


    /**
     * <b> 移除文件中标签
     * </b><br><br><i>Description</i> :
     * @param noteId Integer，labelIds -List: Integer
     * @return com.dxl.base.Result int
     * <br><br>Date: 2019-09-25    <br>Author : dxl
     */
    @Override
    @Transactional
    public Result delLabelFromNote(Integer noteId, List<Integer> labelIds) {
        int num = 0;
        for(Integer labelId : labelIds){
            LabelNote labelNote = new LabelNote();
            labelNote.setNoteId(noteId);
            labelNote.setLabelId(labelId);
            QueryWrapper<LabelNote> labelNoteWrapper = new QueryWrapper<LabelNote>(labelNote);
            labelNoteMapper.delete(labelNoteWrapper);
            num++;
        }
        return Results.successWithData(num);
    }

    /**
     * <b> 移除文件中全部标签
     * </b><br><br><i>Description</i> :
     * @param noteId Integer
     * @return com.dxl.base.Result int
     * <br><br>Date: 2019-09-25    <br>Author : dxl
     */
    @Override
    @Transactional
    public Result delAllLabelFromNote(Integer noteId) {
        LabelNote labelNote = new LabelNote();
        labelNote.setNoteId(noteId);
        QueryWrapper<LabelNote> labelNoteWrapper = new QueryWrapper<LabelNote>(labelNote);
        int num = labelNoteMapper.delete(labelNoteWrapper);
        return Results.successWithData(num);
    }

    /**
     * <b> 编辑文件
     * </b><br><br><i>Description</i> : 不能重复：文件标题-note_title
     * @param note Note
     * @return com.dxl.base.Result Note
     * <br><br>Date: 2019-09-25    <br>Author : dxl
     */
    @Override
    public Result editOne(Note note) {
        note.setNoteTitle(note.getNoteTitle().trim());
        Result result = isNoteEditable(note);
        boolean flag = (boolean) result.getData();
        if(!flag){
            return Results.failure(result.getMsg());
        }
        Note note2 = noteMapper.selectById(note.getId());
        QueryWrapper<Config> configQueryWrapper = new QueryWrapper<>();
        configQueryWrapper.eq("config_key","FileRootPath");
        Config config = configMapper.selectOne(configQueryWrapper);
        if(config == null || config.getConfigKey() == null){
            return Results.failure("系统中无根路径配置，请在数据库中先配置config_key为FileRootPath的记录:(");
        }
        if(config.getConfigValue().substring(config.getConfigValue().length()-1).equals("/")){
            config.setConfigValue(config.getConfigValue().substring(0,config.getConfigValue().length()-1));
        }
        if(!note2.getNoteTitle().equals(note.getNoteTitle())){
            Groups groups = groupsMapper.selectById(note2.getGroupId());
            File file = new File(config.getConfigValue()+"/"+groups.getNote()+"file/"+note2.getNoteTitle()+"."+note2.getTypeSuffix());
            if(file.exists()){
                File fileNew = new File(config.getConfigValue()+"/"+groups.getNote()+"file/"+note.getNoteTitle()+"."+note2.getTypeSuffix());
                file.renameTo(fileNew);
            }
            File file2 = new File(config.getConfigValue()+"/"+groups.getNote()+"html/"+note2.getNoteTitle()+".html");
            if(file2.exists()){
                File fileNew2 = new File(config.getConfigValue()+"/"+groups.getNote()+"html/"+note.getNoteTitle()+".html");
                file2.renameTo(fileNew2);
            }
        }
        if(!note2.getGroupId().equals(note.getGroupId())){
            Groups groups = groupsMapper.selectById(note2.getGroupId());
            File fileOld = new File(config.getConfigValue()+"/"+groups.getNote()+"file/"+note.getNoteTitle()+"."+note2.getTypeSuffix());
            File fileOldHtml = new File(config.getConfigValue()+"/"+groups.getNote()+"html/"+note.getNoteTitle()+".html");
            Groups groupsNew = groupsMapper.selectById(note.getGroupId());
            File fileNew = new File(config.getConfigValue()+"/"+groupsNew.getNote()+"file/"+note.getNoteTitle()+"."+note2.getTypeSuffix());
            File fileNewHtml = new File(config.getConfigValue()+"/"+groupsNew.getNote()+"html/"+note.getNoteTitle()+".html");
            if(!(fileNew.getParentFile().exists())){  //判断d:\demo目录是否存在
                fileNew.getParentFile().mkdir();
            }
            fileOld.renameTo(fileNew);
            fileOldHtml.renameTo(fileNewHtml);
        }
        note.setTypeSuffix(note2.getTypeSuffix());
        noteMapper.updateById(note);
        return Results.successWithData(note);
    }

    /**
     * <b> ID查询文件
     * </b><br><br><i>Description</i> : 
     * @param noteId Integer
     * @return com.dxl.base.Result: Note
     * <br><br>Date: 2019-09-25    <br>Author : dxl
     */
    @Override
    public Result getById(Integer noteId) {
        Note note = noteMapper.selectById(noteId);
        return Results.successWithData(note);
    }

    /**
     * <b> 条件查询文件
     * </b><br><br><i>Description</i> : 
     * @param note Note
     * @return com.dxl.base.Result List: Note
     * <br><br>Date: 2019-09-25    <br>Author : dxl
     */
    @Override
    public Result getList(Note note) {
        QueryWrapper<Note> noteWrapper = new QueryWrapper<>();
        noteWrapper.eq("note.group_id",note.getGroupId());
        List<Note> noteList = noteMapper.getJoinLabelSeries(noteWrapper);
        noteList = handleNote(noteList);
        return Results.successWithData(noteList);
    }

    /**
     * <b> 分页条件查询文件
     * </b><br><br><i>Description</i> : 
     * @param note Note, currentPage -Integer, pageSize -Integer
     * @return com.dxl.base.Result List: Note
     * <br><br>Date: 2019-09-25     <br>Author : dxl
     */
    @Override
    public Result getListByPage(Note note, Integer currentPage, Integer pageSize) {
        PageHelper.startPage(currentPage, pageSize);
        List<Note> noteList = (List<Note>) getList(note).getData();
        PageInfo<Note> pageInfo = new PageInfo<Note>(noteList);
        return Results.successWithData(pageInfo);
    }

    /**
     * <b> 条件查询分组及子分组所有文件
     * </b><br><br><i>Description</i> :
     * @param note Note
     * @return com.dxl.base.Result List: Note
     * <br><br>Date: 2019-09-25    <br>Author : dxl
     */
    @Override
    public Result getListAllInGroup(Note note,List<Integer> groupIdList) {
        QueryWrapper<Note> wrapper = new QueryWrapper<>();
        wrapper.in("note.group_id",groupIdList);
        List<Note> noteList = noteMapper.getJoinLabelSeries(wrapper);
        noteList = handleNote(noteList);
        return Results.successWithData(noteList);
    }

    /**
      * <b> 获得分组下所有子分组ID
      * </b><br><br><i>Description</i> :
      * @param id
      * @return java.util.List<java.lang.Integer>
      * <br><br>Date: 2019/10/1 15:29    <br>Author : dxl
      */
    private List<Integer> getGroupAllId(Integer id){
        List<Integer> groupIdList = new ArrayList<>();
        QueryWrapper<Groups> wrapper = new QueryWrapper<>();
        wrapper.eq("p_id",id);
        List<Groups> groupsList = groupsMapper.selectList(wrapper);
        if(groupsList != null && groupsList.size() > 0){
            groupIdList.addAll(groupsList.stream().map(Groups::getId).collect(Collectors.toList()));
            for(Integer id2 : groupsList.stream().map(Groups::getId).collect(Collectors.toList())){
                groupIdList.addAll(getGroupAllId(id2));
            }
        }else {
            return groupIdList;
        }
        return groupIdList;
    }

    /**
     * <b> 分页条件查询分组及子分组所有文件
     * </b><br><br><i>Description</i> :
     * @param note Note, currentPage -Integer, pageSize -Integer
     * @return com.dxl.base.Result List: Note
     * <br><br>Date: 2019-09-25     <br>Author : dxl
     */
    @Override
    public Result getListAllInGroupByPage(Note note, Integer currentPage, Integer pageSize) {
        List<Integer> groupIdList = getGroupAllId(note.getGroupId());
        groupIdList.add(note.getGroupId());
        PageHelper.startPage(currentPage, pageSize);
        List<Note> noteList = (List<Note>) getListAllInGroup(note,groupIdList).getData();
        PageInfo<Note> pageInfo = new PageInfo<Note>(noteList);
        return Results.successWithData(pageInfo);
    }

    /**
     * <b> 查询文件中全部标签
     * </b><br><br><i>Description</i> : 联表
     * @param noteId Integer
     * @return com.dxl.base.Result List: Label
     * <br><br>Date: 2019-09-25    <br>Author : dxl
     */
    @Override
    public Result getAllLabelInNote(Integer noteId) {
        List<Label> labelList = noteMapper.getAllLabelInNote(noteId);
        labelList = labelService.colorLabel(labelList);
        return Results.successWithData(labelList);
    }

    /**
     * <b> 分页查询文件中全部标签
     * </b><br><br><i>Description</i> : 联表
     * @param noteId Integer, currentPage -Integer, pageSize -Integer
     * @return com.dxl.base.Result List: Label
     * <br><br>Date: 2019-09-25    <br>Author : dxl
     */
    @Override
    public Result getAllLabelInNoteByPage(Integer noteId, Integer currentPage, Integer pageSize) {
        PageHelper.startPage(currentPage, pageSize);
        List<Label> labelList = (List<Label>) getAllLabelInNote(noteId).getData();
        PageInfo<Label> pageInfo = new PageInfo<Label>(labelList);
        return Results.successWithData(pageInfo);
    }

    /**
     * <b> 模糊查询文件
     * </b><br><br><i>Description</i> : 模糊查询；模糊字段(模式：单字段)：全匹配：note_title-文件标题 note-备注
     * @param note Note
     * @return com.dxl.base.Result List: Note
     * <br><br>Date: 2019-09-25    <br>Author : dxl
     */
    @Override
    public Result getLikeNote(Note note) {
        QueryWrapper<Note> noteWrapper = new QueryWrapper<>();
        if(note.getNoteTitle() != null){
            noteWrapper.like("note_title",note.getNoteTitle());
        }else if(note.getNote() != null){
            noteWrapper.like("note",note.getNote());
        }else{
            return Results.failure("请正确填写属性:(");
        }
        List<Note> noteList = null;
        if(note.getNoteTitle() != null && note.getNoteTitle().length() > 1 && note.getNoteTitle().substring(0,1).equals(".")){
            QueryWrapper<Note> noteQueryWrapper = new QueryWrapper<>();
            noteQueryWrapper.eq("type_suffix",note.getNoteTitle().substring(1,note.getNoteTitle().length()));
            noteList = noteMapper.getJoinLabelSeries(noteQueryWrapper);
        }else {
            noteList = noteMapper.getJoinLabelSeries(noteWrapper);
        }

        noteList = handleNote(noteList);
        return Results.successWithData(noteList);
    }
    /**
     * <b> 分页模糊查询文件
     * </b><br><br><i>Description</i> : 模糊查询；模糊字段(模式：单字段)：全匹配：note_title-文件标题 note-备注
     * @param note Note, currentPage -Integer, pageSize -Integer
     * @return com.dxl.base.Result List: Note
     * <br><br>Date: 2019-09-25     <br>Author : dxl
     */
    @Override
    public Result getLikeNoteByPage(Note note, Integer currentPage, Integer pageSize) {
        PageHelper.startPage(currentPage, pageSize);
        List<Note> noteList = (List<Note>) getLikeNote(note).getData();
        PageInfo<Note> pageInfo = new PageInfo<Note>(noteList);
        return Results.successWithData(pageInfo);
    }

    /**
     * <b> 联表查询文件
     * </b><br><br><i>Description</i> : 联表查询，联表：标签文件关联 标签
     * @param note Note
     * @return com.dxl.base.Result List: Note
     * <br><br>Date: 2019-09-29    <br>Author : dxl
     */
    @Override
    public Result getJoinLabelSeries(Note note) {
        QueryWrapper<Note> noteWrapper = new QueryWrapper<Note>(note);
        List<Note> noteList = noteMapper.getJoinLabelSeries(noteWrapper);
        noteList = handleNote(noteList);
        return Results.successWithData(noteList);
    }
    @Override
    public List<Note> handleNote(List<Note> noteList){
        for(Note note1 : noteList){

            if(note1.getSeries() != null){
                note1.setSeriesName("["+note1.getSeries().getSeriesName()+"]");
            }else {
                note1.setSeriesName("");
            }
            if(note1.getLabelList() != null && note1.getLabelList().size() > 0){
                StringBuffer sb = new StringBuffer();
                for(Label label : note1.getLabelList()){
                    sb.append(label.getLabelName()+" | ");
                }
                note1.setLabelListStr(sb.toString().substring(0,sb.toString().length()-3));
            }else {
                note1.setLabelListStr("");
            }
            if(note1.getNote() == null){
                note1.setNote("");
            }
        }
        return noteList;
    }

    /**
     * <b> 分页联表查询文件
     * </b><br><br><i>Description</i> : 联表查询，联表：标签文件关联 标签
     * @param note Note, currentPage -Integer, pageSize -Integer
     * @return com.dxl.base.Result List: Note
     * <br><br>Date: 2019-09-29     <br>Author : dxl
     */
    @Override
    public Result getJoinLabelSeriesByPage(Note note, Integer currentPage, Integer pageSize) {
        PageHelper.startPage(currentPage, pageSize);
        List<Note> noteList = (List<Note>) getJoinLabelSeries(note).getData();
        PageInfo<Note> pageInfo = new PageInfo<Note>(noteList);
        return Results.successWithData(pageInfo);
    }

    /**
     * <b> 文件能否新增
     * </b><br><br><i>Description</i> : 不能为空：文件标题-note_title ；不能重复：文件标题-note_title
     * @param note Note
     * @return com.dxl.base.Result boolean
     * <br><br>Date: 2019-09-25     <br>Author : dxl
     */
    @Override
    public Result isNoteAddable(Note note) {

        if(note.getNoteTitle() == null){
            return Results.successWithData(false,"文件标题 不能为空:(");
        }
        if(note.getGroupId() == null){
            return Results.successWithData(false,"分组 不能为空:(");
        }

        if(note.getNoteTitle() != null){
        QueryWrapper<Note> noteWrapper = new QueryWrapper<>();
        noteWrapper.eq("note_title",note.getNoteTitle());
        noteWrapper.eq("group_id",note.getGroupId()).eq("type_suffix",note.getTypeSuffix());
        List<Note> noteList = noteMapper.selectList(noteWrapper);
            if(noteList.size() > 0){
                return Results.successWithData(false,"此分组中文件标题 重复:(");
            }
        }

        return Results.successWithData(true,"无重复:)");
    }

    /**
     * <b> 文件能否编辑
     * </b><br><br><i>Description</i> : 不能重复：文件标题-note_title
     * @param note Note
     * @return com.dxl.base.Result boolean
     * <br><br>Date: 2019-09-25     <br>Author : dxl
     */
    @Override
    public Result isNoteEditable(Note note) {

        if(note.getNoteTitle() != null){
            QueryWrapper<Note> noteWrapper1 = new QueryWrapper<>();
            noteWrapper1.eq("id",note.getId()).eq("note_title",note.getNoteTitle()).eq("group_id",note.getGroupId()).eq("type_suffix",note.getTypeSuffix());
            List<Note> noteList1 = noteMapper.selectList(noteWrapper1);
            QueryWrapper<Note> noteWrapper2 = new QueryWrapper<>();
            noteWrapper2.eq("note_title",note.getNoteTitle()).eq("group_id",note.getGroupId()).eq("type_suffix",note.getTypeSuffix());
            List<Note> noteList2 = noteMapper.selectList(noteWrapper2);
            if(!((noteList1.size() == 1 && noteList2.size() == 1) ||(noteList1.size() == 0 && noteList2.size() == 0))){
                return Results.successWithData(false,"文件标题 重复:(");
            }
        }

        return Results.successWithData(true,"无重复:)");
    }
}
